package com.gx.smart.building.ui.photo.activity;

import androidx.annotation.NonNull;

import com.gx.smart.building.ui.photo.fragment.PhotoPreviewFragment;
import com.orhanobut.logger.Logger;
import com.previewlibrary.GPreviewActivity;
import com.previewlibrary.enitity.IThumbViewInfo;
import com.previewlibrary.view.BasePhotoFragment;

import java.util.List;

/**
 * @author xiaosy
 * @create 2020/7/30
 * @Describe
 **/
public class CustomActivity extends GPreviewActivity {

    private int currentIndex;

    @Override
    protected void iniFragment(List<IThumbViewInfo> imgUrls, int currentIndex, Class<? extends BasePhotoFragment> className) {
        Logger.d("imgUrls:" + imgUrls.get(0).getUrl());
        this.currentIndex = currentIndex;
        if (imgUrls != null) {
            int size = imgUrls.size();
            for (int i = 0; i < size; i++) {
                getFragments().add(PhotoPreviewFragment.
                        getInstance(className, imgUrls.get(i),
                                currentIndex == i,
                                getIntent().getBooleanExtra("isSingleFling", false),
                                getIntent().getBooleanExtra("isDrag", false),
                                getIntent().getFloatExtra("sensitivity", 0.5f))
                );
            }
        } else {
            finish();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PhotoPreviewFragment fragment = (PhotoPreviewFragment) getFragments().get(currentIndex);
        fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
